//#include "stdafx.h"
#include "LeafNodeModel.h"

CLeafNodeModel::CLeafNodeModel(void)
{
}

CLeafNodeModel::~CLeafNodeModel(void)
{
}

int	CLeafNodeModel::SaveLeafNodeModel(FILE *fpFile)
{
	fprintf(fpFile, "%6d %12.6f\n", LeafNodeID, ori);
	////fprintf(fpFile, "%6d %12.6f %6d\n", LeafNodeID, ori, (int) Weights.size());
	////for ( int i = 0; i < (int) Weights.size(); i++ )
	////{
	////	fprintf(fpFile, "%12.6f %12.6f %12.6f %12d %12.6f\n", Weights[i], FeatureModel[i].MaxValue, FeatureModel[i].MinValue, FeatureModel[i].BinSize, FeatureModel[i].Smooth);
	////	for ( int j = 0; j < (int) FeatureModel[i].BinSize; j++ )
	////	{
	////		fprintf(fpFile, "%12.6f ", FeatureModel[i].BinValue[j]);
	////	}
	////	fprintf(fpFile, "\n");
	////}
	////fprintf(fpFile, "\n");

	return	1;
}

int CLeafNodeModel::ReadLeafNodeModel(FILE *fpFile)
{
	fscanf_s(fpFile, "%d%lf", &LeafNodeID, &ori);
	////int		Dim;
	////fscanf_s(fpFile, "%d%lf%d", &LeafNodeID, &ori, &Dim);
	////FeatureModel.resize(Dim);
	////Weights.resize(Dim);
	////for ( int i = 0; i < Dim; i++ )
	////{
	////	fscanf_s(fpFile, "%lf%lf%lf%d%lf", &Weights[i], &FeatureModel[i].MaxValue, &FeatureModel[i].MinValue, &FeatureModel[i].BinSize, &FeatureModel[i].Smooth);
	////	FeatureModel[i].BinValue.resize(FeatureModel[i].BinSize);
	////	for ( int j = 0; j < (int) FeatureModel[i].BinSize; j++ )
	////	{
	////		fscanf_s(fpFile, "%lf", &FeatureModel[i].BinValue[j]);
	////	}
	////}

	return	1;
}

////int CLeafNodeModel::ConvertFeature(vector<double> &inFeature, vector<double> &outFeature)
////{
////	outFeature.resize(FeatureModel.size());
////	for ( int i = 0; i < (int) FeatureModel.size(); i++ )
////	{
////		double	Step	= (FeatureModel[i].MaxValue - FeatureModel[i].MinValue) / FeatureModel[i].BinSize;
////
////		if ((inFeature[i] < FeatureModel[i].MinValue) || (inFeature[i] > FeatureModel[i].MaxValue))
////		{
////			outFeature[i]	= FeatureModel[i].Smooth;
////		}
////		else
////		{
////			int		BinID	= __max(0, __min(FeatureModel[i].BinSize - 1, int((inFeature[i] - FeatureModel[i].MinValue) / Step + 0.5)));
////
////			outFeature[i]	= FeatureModel[i].BinValue[BinID];
////		}
////
////		int tt = (int)((inFeature[i] - FeatureModel[i].MinValue) / Step);
////		tt = (tt<0 ? 0 : (tt>=FeatureModel[i].BinSize ? FeatureModel[i].BinSize-1 : tt));
////		outFeature[i] = FeatureModel[i].BinValue[tt];
////	}
////
////	return	1;
////}